import { supabase } from '../lib/supabaseClient'

// 获取所有食谱种类
export const getRecipeTypes = async () => {
  const { data, error } = await supabase.from('recipeType').select()
  if (error) {
    throw error
  }
  return data
}

// 创建新食谱种类
export const createRecipeType = async (recipeTypeData) => {
  const { data, error } = await supabase
    .from('recipeType')
    .insert([recipeTypeData])
    .select()
  
  if (error) {
    throw error
  }
  return data[0]
}

// 更新食谱种类
export const updateRecipeType = async (id, recipeTypeData) => {
  const { data, error } = await supabase
    .from('recipeType')
    .update(recipeTypeData)
    .eq('id', id)
    .select()
  
  if (error) {
    throw error
  }
  return data[0]
}

// 删除食谱种类
export const deleteRecipeType = async (id) => {
  const { error } = await supabase
    .from('recipeType')
    .delete()
    .eq('id', id)
  
  if (error) {
    throw error
  }
  return true
}
